package cn.ffcs.uec.outStaffEntryApply.component;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zul.Div;
import org.zkoss.zul.ListModel;

import cn.ffcs.uec.outStaffEntryApply.component.bean.OutStaffEntryHistoricFlowListboxExtBean;
import cn.ffcs.uec.recordsApproval.constant.ApprovalConstants;
import cn.ffcs.uec.recordsApproval.util.ApprovalUtil;
import cn.ffcs.uec.recordsApproval.vo.HistoricFlow;
import cn.ffcs.uec.recordsApproval.vo.TaskVo;
import lombok.Getter;

/**
 * 流程流转信息
 * @author liuxiaodong
 *
 */
@Controller
@Scope("prototype")
public class OutStaffEntryHistoricFlowListboxExt extends Div implements IdSpace {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6163886240219881836L;
	
	@Getter
	private OutStaffEntryHistoricFlowListboxExtBean bean = new OutStaffEntryHistoricFlowListboxExtBean();
	
	public static final String OUT_STAFF_ENTRY_HISTORIC_FLOW_LISTBOX_EXT = 
			"/pages_nmg/outStaffEntryApply/comp/outStaffEntryHistoricFlow_listbox_ext.zul";
		

	/**
	 * 从outStaffEntryApprovalListboxExt 接收事件的值
	 */
	private TaskVo task;
	
	
	
	/**
	 * 构造函数
	 */
	public OutStaffEntryHistoricFlowListboxExt() {
		Executions.createComponents(OUT_STAFF_ENTRY_HISTORIC_FLOW_LISTBOX_EXT, this, null);
		Components.wireVariables(this, bean);
		Components.addForwards(this, this, '$');
		
		this.addForward(ApprovalConstants.ON_SELECTED_HISTORIC_FLOW, this, ApprovalConstants.ON_SELECTED_HISTORIC_FLOW_RESPONSE);
	}

	/**
	 * 初始化
	 */
	public void onCreate() {
		
	}
	
	
	public void onSelectHistoricFlowResponse(ForwardEvent event) {
		task = (TaskVo) event.getOrigin().getData();
		if(null != task) {
			String procInstId = task.getProcInsId();
			List<HistoricFlow> historicFlows = ApprovalUtil.historicFlow(procInstId);
			
			ListModel dataList = new BindingListModelList(historicFlows, true);
			bean.getOutStaffEntryHistoricFlowListbox().setModel(dataList);
		}
	}

}
